/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entitys;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Persistence;

@Entity
/**
 *
 * @author usuarios
 */
public class MedicalRecord implements Serializable {

    @Id
    private Long idMR;
    @OneToOne(cascade=CascadeType.PERSIST)
    private Pet pet;
    @OneToMany (cascade=CascadeType.PERSIST)
    private List<Vacine> vacineList = new ArrayList<>();
    @OneToMany(cascade = CascadeType.PERSIST)
    private List<Appointment> appointmentList = new ArrayList<>();
    
    public List<Vacine> getvacine(){
        return vacineList;
    }
    
    public void setvacine(List<Vacine> vacineList){
        this.vacineList = vacineList;
    }
    
    public List<Appointment> getappointment(){
        return appointmentList;
    }
    
    public void setappointment(List<Appointment> appointmentList){
        this.appointmentList = appointmentList;
    }

    public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("HPVAPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }

    public Long getId() {
        return idMR;
    }

    public void setId(Long idMR) {
        this.idMR = idMR;
    }
    
}
